#pragma once

#include<iostream>
#include<string>
#include<pthread.h>
#include<ctime>

typedef void(*cab)();
static int num = 1;


class Thread
{
public:
    static void* Routine(void* args)
    {
        Thread* td = static_cast<Thread*> (args);
        td->entry();
    }
public:
    Thread(cab cb)
    :_tid(0),_name(""),_time(0),_IsRunning(false),_cb(cb)
    {}
    ~Thread()
    {}
    void run()
    {
        _name = "thread-" + std::to_string(num++);
        _IsRunning = true;
        _time = time(nullptr);
        pthread_create(&_tid,nullptr,Routine,this);
    }
    void Join()
    {
        pthread_join(_tid,nullptr);
        _IsRunning = false;
    }


    void entry()
    {
        _cb();
    }

    bool status()
    {
        return _IsRunning;
    }
    uint64_t StartTimestamp()
    {
        return time(nullptr);
    }

private:
    pthread_t _tid;
    std::string _name;
    uint64_t _time;
    bool _IsRunning;
    cab _cb;

};